package pers.mtx.hmw;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

public class auto {
    public static void main(String[] args) {
        FastAutoGenerator.create(new DataSourceConfig.Builder("jdbc:postgresql://localhost:5432/hmw", "postgres", "mysecretpassword").schema("user"))
                .globalConfig(builder -> {
                    builder.author("mtx") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("/home/mtx/code/软件开发课程/web-framework/hmw/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("pers.mtx") // 设置父包名
                            .moduleName("hmw") // 设置父包模块名
                            .xml("mapper")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "/home/mtx/code/软件开发课程/web-framework/hmw/src/main/resources")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("users") // 设置需要生成的表名
                            .addTablePrefix("t_", "c_")
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImmpl")
                            .entityBuilder()
                            .enableLombok()
                            .logicDeleteColumnName("deleted")
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .formatFileName("%sController")
                            .enableRestStyle()
                            .mapperBuilder()
                            .superClass(BaseMapper.class)
                            .formatMapperFileName("%sMapper")
                            .enableMapperAnnotation()
                            .formatXmlFileName("%sMapper");
                })
//                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
